﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Senparc.Weixin.MP.Entities;
using System.Net.Mail;
using System.Net;

namespace Weixin.Sample
{
    public partial class WMessageHandler
    {
        public override IResponseMessageBase OneEvent_MassSendJobFinisRequest(RequestMessageEvent_MassSendJobFinish requestMessage)
        {
            return base.OneEvent_MassSendJobFinisRequest(requestMessage);
        }

        /// <summary>
        /// 订阅事件
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = Utitly.SubscribeContent;
            return responseMessage;
        }

        /// <summary>
        /// 取消订阅,理论上用户已收不到回应
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            try
            {
                MailMessage _message = new MailMessage();
                _message.From = new MailAddress("wangx.freesoft@gmail.com", "weixin");
                _message.To.Add(new MailAddress("277432742@qq.com"));
                _message.Subject = requestMessage.FromUserName + "取消关注";
                _message.BodyEncoding = System.Text.Encoding.UTF8;
                _message.Body = requestMessage.FromUserName + "取消关注";

                SmtpClient sc = new SmtpClient("smtp.gmail.com");
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                sc.UseDefaultCredentials = true;
                sc.EnableSsl = true;
                sc.Credentials = new NetworkCredential("wangx.freesoft@gmail.com", "wx20110624wx");
                sc.Send(_message);
            }
            catch { }

            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "有空再来";
            return responseMessage;
        }

        /// <summary>
        /// 扫描二维码
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ScanRequest(RequestMessageEvent_Scan requestMessage)
        {
            return base.OnEvent_ScanRequest(requestMessage);
        }

        /// <summary>
        /// 上传地理位置
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_LocationRequest(RequestMessageEvent_Location requestMessage)
        {
            return base.OnEvent_LocationRequest(requestMessage);
        }

        /// <summary>
        /// 自定义菜单单击
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            switch (requestMessage.EventKey)
            {

            }

            return base.OnEvent_ClickRequest(requestMessage);
        }

        /// <summary>
        /// 自定义菜单跳转链接
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ViewRequest(RequestMessageEvent_View requestMessage)
        {
            return base.OnEvent_ViewRequest(requestMessage);
        }
    }
}